﻿using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Company.BLL;
using Company.BLL.DuLieuChuan;
using Company.Controls;

namespace Company.Interface
{
	public partial class BaseForm : Form
    {
        public string MaDoanhNghiep;
        public string MaHaiQuan;
	    public OpenFormType OpenType;
        public string CalledForm = string.Empty;

        protected MessageBoxControl _MsgBox;
        protected DataTable _DonViTinh;
        protected DataTable _DonViHaiQuan;
        protected DataTable _LoaiHinhMauDich;
        protected DataTable _NguyenTe;
        protected DataTable _Nuoc;
        protected DataTable _PhuongThucThanhToan;
        protected DataTable _PhuongThucVanTai;
        protected DataTable _DieuKienGiaoHang;
        protected DataTable _NhomSanPham;
        protected DataTable _LoaiPhuKien;
		private IContainer components = null;

        public string ShowMessage(string message, bool showYesNoButton)
        {
            this._MsgBox = new MessageBoxControl();
            this._MsgBox.ShowYesNoButton = showYesNoButton;
            this._MsgBox.MessageString = message;
            this._MsgBox.ShowDialog();
            return this._MsgBox.ReturnValue;
        }
       
		public BaseForm()
		{
			InitializeComponent();
        }

        #region Dữ liệu chuẩn.

        public string Nuoc_GetName(object id)
        {
            if (_Nuoc == null) _Nuoc = Nuoc.SelectAll();
            return this._Nuoc.Select(string.Format("ID = '{0}'", id.ToString().PadRight(3)))[0][1].ToString();
        }
	    
        protected string DonViTinh_GetName(object id)
        {
            if (this._DonViTinh == null) this._DonViTinh = DonViTinh.SelectAll();
            return this._DonViTinh.Select(string.Format("ID = '{0}'", id.ToString().PadRight(3)))[0][1].ToString();
        }
        protected string DonViTinh_GetID(string ten)
        {
            if (this._DonViTinh == null) this._DonViTinh = DonViTinh.SelectAll();
            return this._DonViTinh.Select(string.Format("Ten = '{0}'", ten))[0][0].ToString();
        }
        protected string DonViHaiQuan_GetName(object id)
        {
            if (_DonViHaiQuan == null) _DonViHaiQuan = DonViHaiQuan.SelectAll();
            return this._DonViHaiQuan.Select(string.Format("ID = '{0}'", id.ToString().PadRight(6)))[0][1].ToString();
        }
        protected string LoaiHinhMauDich_GetTenVT(object id)
        {
            if (_LoaiHinhMauDich == null) _LoaiHinhMauDich = LoaiHinhMauDich.SelectAll();
            return this._LoaiHinhMauDich.Select(string.Format("ID = '{0}'", id.ToString().PadRight(5)))[0][2].ToString();
        }
        protected string LoaiHinhMauDich_GetName(object id)
        {
            if (_LoaiHinhMauDich == null) _LoaiHinhMauDich = LoaiHinhMauDich.SelectAll();
            return this._LoaiHinhMauDich.Select(string.Format("ID = '{0}'", id.ToString().PadRight(5)))[0][1].ToString();
        }
        protected string NhomSanPham_GetName(object id)
        {
            if (_NhomSanPham == null) _NhomSanPham = NhomSanPham.SelectAll().Tables[0];
            return this._NhomSanPham.Select(string.Format("MaSanPham = '{0}'", id.ToString().PadRight(5)))[0][2].ToString();
        }
        protected string LoaiPhuKien_GetName(object id)
        {
            if (_LoaiPhuKien == null) _LoaiPhuKien = Company.BLL.DuLieuChuan.LoaiPhuKien.SelectAll();
            return this._LoaiPhuKien.Select(string.Format("ID_LoaiPhuKien = '{0}'", id.ToString().PadRight(3)))[0][1].ToString();
        }

        protected string NguyenTe_GetName(object id)
        {
            if (_NguyenTe == null) _NguyenTe = Company.BLL.DuLieuChuan.NguyenTe.SelectAll();
            return this._NguyenTe.Select(string.Format("ID = '{0}'", id.ToString().PadRight(3)))[0][1].ToString();
        }
        #endregion
    }
}